import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { Footer } from './../index'

import './resumerList.less'

class ResumerList extends Component {

    constructor() {
        super()
        this.state = {
            genderArr: ['性别未知', '男', '女'],
            educationArr: ['未知', '小学', '初中', '中专', '高中', '大学专科', '大学本科', '硕士', '博士', '博士后', '其它'],
        }
    }

    componentWillReceiveProps(nextProps) {
        console.log(this.props, nextProps)
    }

    componentWillUnmount() { }

    componentDidShow() { }

    componentDidHide() { }

    toResumeInfo(id, e) {
        Taro.navigateTo({
            url: '/subPackages/subPackageF/resumeInfo/resumeInfo?workerId=' + id
        })
    }

    jsGetAge(strBirthday) {
        let returnAge;
        //以下五行是为了获取出生年月日，如果是从身份证上获取需要稍微改变一下
        let strBirthdayArr = strBirthday.split("-");
        let birthYear = strBirthdayArr[0];
        let birthMonth = strBirthdayArr[1];
        let birthDay = strBirthdayArr[2];

        let d = new Date();
        let nowYear = d.getFullYear();
        let nowMonth = d.getMonth() + 1;
        let nowDay = d.getDate();
        if (nowYear == birthYear) {
            returnAge = 0;//同年 则为0岁
        } else {
            let ageDiff = nowYear - birthYear; //年之差
            if (ageDiff > 0) {
                if (nowMonth == birthMonth) {
                    let dayDiff = nowDay - birthDay;//日之差
                    if (dayDiff < 0) {
                        returnAge = ageDiff - 1;
                    } else {
                        returnAge = ageDiff;
                    }
                }
                else {
                    let monthDiff = nowMonth - birthMonth;//月之差
                    if (monthDiff < 0) {
                        returnAge = ageDiff - 1;
                    } else {
                        returnAge = ageDiff;
                    }
                }
            }
            else {
                returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
            }
        }
        return returnAge;//返回周岁年龄
    }

    render() {
        let { resumerListAll } = this.props
        let { genderArr, educationArr, experienceArr } = this.state
        return (
            <View className='resumerPool'>
                {
                    resumerListAll && resumerListAll.length > 0 && resumerListAll.map((item, index) =>
                        <View className='resumerList' onClick={this.toResumeInfo.bind(this, item.worker_id)}>
                            <View className='headBlock'>
                                <View className='headImg'><Image src={item.worker_avatar}></Image></View>
                            </View>
                            <View className='conBlock'>
                                <View className='title'>{item.worker_nickname}
                                    {item.is_buy == 'true' && <View className='hasContact centerFlex'>已购买</View>}
                                </View>
                                <View className='about'>
                                    <View className='item'>{genderArr[item.worker_gender]}</View>
                                    <View className='gang'></View>
                                    <View className='item'>{this.jsGetAge(item.worker_birthday)}岁</View>
                                    <View className='gang'></View>
                                    <View className='item'>{educationArr[item.worker_education]}</View>
                                    <View className='gang'></View>
                                    {item.worker_experience > 0 ? <View className='item'>{item.worker_experience}年</View> : <View className='item'>无经验</View>}
                                </View>
                                <View className='about'>
                                    <View>在找</View>
                                    <View className='position'>{item.position_title}</View>
                                </View>
                            </View>
                        </View>
                    )
                }
                <Footer></Footer>
            </View>
        )
    }
}

export default ResumerList
